JUMPING ROUTINE

RAM variables:
$0754: in_elevator (boolean)
$A7: collision bits for Link - 0000ABLR (above,below,left,right)
$0479: jumping_state (2=going up, 1=coming down, 0=not jumping)
$03E6: gravity_counter (each time it overflows, vspeed += 1)
$057D: vspeed (Link's vertical velocity, negative is up.)
$0029: y_pos (Link's y position in sideview)
$0400: sword_slash_frame (animation frame)
$0497: crouch_timer (timer for Link crouching after landing)
$0070: hspeed (Link's horizontal velocity)
$00D0: jump_spell_on (0=off, 1=on)
$0019: fall_or_invisible (0=invisible, 1=normal, 2~FF=fall in hole)
$0000: argument0 (gravitational force (speed of gravity counter))
$0002: argument2 (max vspeed falling)

Tables in ROM:
bank 0, $9470 (rom 0x1480): speed_list = hex[FB FB FC FC] = dec[-5 -5 -4 -4]
bank 0, $9474 (rom 0x1484): gravity_counter_list = hex[80 00 F0 80]

CODE:
LABEL $94C5 (rom 0x14D5)
if in_elevator:
    return
if collision<below> == false:
    if jumping_state == 0:
        jumping_state++
    goto $952D
if jumping_state != 0:
    if vspeed < 0:
        goto $952D
    if vspeed >= 5:
        crouch_timer = 8
    jumping_state = 0
    vspeed = 0
    sword_slash_frame = 0
y_pos = y_pos AND F0 //Snap to vertical 16-pixel grid
if buttonPressed('A') == false:
    return
index = 0 //really this is register Y
sword_slash_frame = 0
jumping_state = 0
if hspeed + 13 < 26:
    index++
if jump_spell_on == false:
    index += 2
vspeed = speed_list[index]
gravity_counter = gravity_counter_list[index]
jumping_state = 2

LABEL $952D
index = 48
if buttonHeldDown('A') == true:
    if vspeed < 0:
        index = 30
argument0 = index
argument2 = 5
registerX = 0
if vspeed < 0
    if collision<above> == true:
        if vspeed + 1 < 0:
            vspeed = FF //FF = -1
            gravity_counter = 0 //it’s actually vspeed+1 but FF+1 = 0
        push(y_pos)
        applyGravityMotion()
        y_pos = pop(y_pos)
        goto $956C
applyGravityMotion() //don't preserve y position

LABEL $956C
if jumping_state - 1 != 0:
    //handle upthrust
//handle downthrust

SUBROUTINE applyGravityMotion():

LABEL $D19B (rom 0x1D1AB)
index = 0
if vspeed < 0:
    index = FF
y_pos += vspeed
fall_or_invisible += index
gravity_counter += argument0
vspeed += CARRYFLAG //1 or 0 from previous addition operation
if vspeed == argument2:
    vspeed = vspeed (?)
    gravity_counter = 0
return